Skip to content

ensure draft chat spec is updated when update_current_session tool is called - #1342

Merged
heerambavi1998 merged 3 commits into
mainfrom
ha/ui-update_session_tool
Nov 12, 2026
Merged

heerambavi1998 merged 3 commits into
mainfrom
ha/ui-update_session_tool

Conversation

@heerambavi1998

@heerambavi1998 heerambavi1998 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes AGE-2765


Note

Medium Risk
Touches draft session sync and message scanning during agent runs; logic is scoped to draft mode with deduplication guards, but incorrect detection could skip or double-reload specs.

Overview
Draft chat sessions now reload the stored agent spec when the agent finishes a TrueForge update_current_session tool call during an active run, so UI state stays in sync when the backend rewrites the session spec.

This adds findLatestSessionSpecUpdate to detect completed call_tool invocations targeting built-in:trueforge-mcp / update_current_session (ignoring other servers, direct calls, and in-flight tools), exposes reloadAgentSpec on the draft spec hook to re-fetch from the draft bridge, and wires a runtime effect that reloads once per new tool call id after the session has run in the current mount—avoiding redundant reloads for history loaded on open and race cases when streaming ends in the same batch as the tool result.

Reviewed by Cursor Bugbot for commit 81d66c2. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 81d66c2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@veria-ai

veria-ai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@heerambavi1998
heerambavi1998 enabled auto-merge (squash) November 12, 2026 07:55
@heerambavi1998
heerambavi1998 merged commit 98f20e6 into main Nov 12, 2026
18 checks passed
@heerambavi1998
heerambavi1998 deleted the ha/ui-update_session_tool branch November 12, 2026 08:00

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 81d66c2. Configure here.

} catch (error) {
onError?.(error);
}
}, [adoptAgentSpec, draftBridge, draftSessionId, onError]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overlapping reloads can apply a stale spec

Medium Severity

reloadAgentSpec does not ignore stale in-flight fetches. Each finished update_current_session starts a new GET, and adoptAgentSpec always applies whichever response returns last. A slower first fetch can overwrite a later spec, so the draft UI can miss the most recent agent edit.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 81d66c2. Configure here.

} catch (error) {
onError?.(error);
}
}, [adoptAgentSpec, draftBridge, draftSessionId, onError]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In-flight spec sync can clobber agent updates

Medium Severity

reloadAgentSpec adopts the GET result without stopping a PATCH that is already in flight. Clearing inFlightFlushRef only drops the local promise; a debounced user syncAgentSpec can still complete afterward and overwrite the spec update_current_session just wrote, leaving the UI and server disagreeing.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 81d66c2. Configure here.

handledSessionSpecUpdateIdRef.current = sessionSpecUpdateId;
if (agent.mode === 'draft') {
void reloadAgentSpec();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paused turns skip the spec reload

Medium Severity

The reload effect treats any update_current_session seen before isRunning as historical and never fetches again. A session opened while paused (for example waiting on approval) never sets that flag, so when the tool later finishes the new spec is marked handled and the draft UI stays on the old spec.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 81d66c2. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants